package com.yong.sbd.biz.mybatis.mapper;

import com.yong.sbd.biz.mybatis.entity.SysUser;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * 用户Mapper接口
 *
 * @author Kang Yong
 * @date 2025/10/24
 * @since 1.0.0
 */
@Mapper
public interface SysUserMapper {

    /**
     * 根据ID查询用户
     *
     * @param id {@link Long}
     * @return {@link SysUser}
     */
    @Select("SELECT * FROM sys_user WHERE id = #{id}")
    SysUser selectById(Long id);

    /**
     * 根据用户名查询用户
     *
     * @param username {@link String}
     * @return {@link SysUser}
     */
    @Select("SELECT * FROM sys_user WHERE username = #{username}")
    SysUser selectByUsername(String username);

    /**
     * 查询所有用户
     *
     * @return {@link List<SysUser>}
     */
    @Select("SELECT * FROM sys_user")
    List<SysUser> selectAll();

    /**
     * 插入用户
     *
     * @param user {@link SysUser}
     * @return int
     */
    @Insert("INSERT INTO sys_user(username, password, email, phone, status) " +
            "VALUES(#{username}, #{password}, #{email}, #{phone}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(SysUser user);

    /**
     * 更新用户
     *
     * @param user {@link SysUser}
     * @return int
     */
    @Update("UPDATE sys_user SET username=#{username}, password=#{password}, " +
            "email=#{email}, phone=#{phone}, status=#{status}, update_time=NOW() WHERE id=#{id}")
    int update(SysUser user);

    /**
     * 根据ID删除用户
     *
     * @param id {@link Long}
     * @return int
     */
    @Delete("DELETE FROM sys_user WHERE id = #{id}")
    int deleteById(Long id);
}